﻿<%@ Page Title="Title" Language="C#" Inherits="System.Web.Mvc.ViewPage<object>" MasterPageFile="~/Views/Shared/Site.Master" %>

<%@ Register TagPrefix="o" Namespace="Omu.AwesomeWebForms" Assembly="Omu.AwesomeWebForms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e8b65a0968999f7e" %>
<%@ Register TagPrefix="o" Namespace="Omu.AwesomeWebForms" Assembly="Omu.AwesomeWebForms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e8b65a0968999f7e" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">
</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
    <h3>
        AjaxList</h3>
    <form runat="server">
    <% 
        FruitsList.Buttons = new[]
                              {
                                  new AjaxListButton {Content = "id", JsFunc = "alert", CssClass = "something"}
                              };
        FruitsList.Data = new Dictionary<string, string> { { "search", Name.ClientID } };
        FruitsList.SearchButton = "bsearch";
    %>
    <div style="float: right; width: 300px;margin:1em;">
        <asp:TextBox runat="server" ID="Name"></asp:TextBox>
        <input type="button" id="bsearch" value="search" />
        <o:AjaxList runat="server" ID="FruitsList" SearchUrl='~/svc/aja.svc/FruitSearch' />
    </div>
    </form>
    <p class="te">
    This control requires a single <b>SearchUrl</b> which must return a LookupResult object, just like Lookup's SearchUrl.
    <br/>
    The AjaxRadioList can be bound to parents (using Data) and predefined values can be sent. The parents thing is useful here for adding search criterias.
    To be able to trigger the search you assign a value to the <b>SearchButton</b> property (the ClientID of the button).
    <br/>
    example:
    </p>
    <pre class="prettyprint">

&lt;%
    FruitsList.Data = new Dictionary&lt;string, string&gt; { { &quot;search&quot;, Name.ClientID } };
    FruitsList.SearchButton = &quot;bsearch&quot;;
%&gt;

&lt;asp:TextBox runat=&quot;server&quot; ID=&quot;Name&quot;&gt;&lt;/asp:TextBox&gt;
&lt;input type=&quot;button&quot; id=&quot;bsearch&quot; value=&quot;search&quot; /&gt;
&lt;o:AjaxList runat=&quot;server&quot; ID=&quot;FruitsList&quot; SearchUrl='~/svc/aja.svc/FruitSearch' /&gt;
    </pre>
    <pre class="prettyprint">
[WebGet]
[OperationContract]
public LookupResult FruitSearch(string search, int page)
{
    var items = Fruits.Where(o =&gt; o.Name.Contains(search))
        .Select(f =&gt; new KeyContent { Key = f.Id, Content = f.Name });

    const int pageSize = 5;
    return new LookupResult
    {
        Items = items.Skip((page - 1) * pageSize).Take(pageSize),
        More = items.Count() &gt; page * pageSize
    };
}
    </pre>
    <h3>Adding buttons</h3>
    <p class="te">
    Buttons can be added, and for each button a custom javascript function can be assigned, that js function will receive the key of the row as a parameter 
    (key from KeyContent from LookupResult.Items). A css class can also be added for each button.<br/>
    example:
    </p>
    <pre class="prettyprint">
FruitsList.Buttons = new[]
{
    new AjaxListButton {Content = &quot;id&quot;, JsFunc = &quot;alert&quot;, CssClass = &quot;something&quot;}
};
    </pre>
    <script type="text/javascript">
        $(function () {
            prettyPrint();
        });
    </script>
</asp:Content>
